package net.diaowen.dwsurvey.controller.survey;

import net.diaowen.common.base.entity.User;
import net.diaowen.common.base.service.AccountManager;
import net.diaowen.common.plugs.httpclient.HttpResult;
import net.diaowen.dwsurvey.entity.SurveyDirectory;
import net.diaowen.dwsurvey.service.SurveyDirectoryManager;
import net.diaowen.dwsurvey.service.SurveyTodoTaskManager;
import net.diaowen.dwsurvey.vo.AddTodoTaskVO;
import net.diaowen.dwsurvey.vo.FinishTodoTaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/dwsurvey/app/survey/todo/")
public class SurveyTodoTaskController {

    @Autowired
    private AccountManager accountManager;
    @Autowired
    private SurveyDirectoryManager surveyDirectoryManager;
    @Autowired
    private SurveyTodoTaskManager surveyTodoTaskManager;

    /**
     * 创建代办
     * @param addTodoTaskVO
     * @return
     */
    @RequestMapping(value = "/add.do",method = RequestMethod.POST)
    @ResponseBody
    public HttpResult add(@RequestBody AddTodoTaskVO addTodoTaskVO) {
        try{
            User curUser = accountManager.getCurUser();
            surveyTodoTaskManager.saveByAdmin(addTodoTaskVO, curUser);
            return HttpResult.SUCCESS();
        }catch (Exception e){
            e.printStackTrace();
        }
        return HttpResult.FAILURE();
    }

    /**
     * 完成代办
     * @param finishTodoTaskVO
     * @return
     */
    @RequestMapping(value = "/finish.do",method = RequestMethod.POST)
    @ResponseBody
    public HttpResult add(@RequestBody FinishTodoTaskVO finishTodoTaskVO) {
        try{
            User curUser = accountManager.getCurUser();
            surveyTodoTaskManager.finish(finishTodoTaskVO);
            return HttpResult.SUCCESS();
        }catch (Exception e){
            e.printStackTrace();
        }
        return HttpResult.FAILURE();
    }

}
